package main

import (
	"fmt"
	"time"
)

func sum(a []int, c chan int) {

	sum := 0

	for _, v := range a {
		sum += v
	}
	c <- sum
}

func main() {
	a := []int{1, 2, 3, 4, 5, 6}

	c := make(chan int)
	go sum(a[:3], c)
	time.Sleep(time.Second)
	go sum(a[3:], c)
	time.Sleep(time.Second)
	go sum(a[:4], c)
	x, y, z := <-c, <-c, <-c
	fmt.Println(x, y, z)
}

//==============================================
//异步执行多线程，结果输出随机，time.Sleep(time.Second)使输出结果有序
